package com.dwh.exception;

import org.springframework.web.bind.annotation.ControllerAdvice;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.ResponseBody;

import com.dwh.msg.Result;

@ControllerAdvice
public class UserExceptionHandle {

	@ExceptionHandler
	@ResponseBody
	public Result<Object> exceptionHandler(Exception e) {
		Result<Object> result = new Result<>();
		if (e instanceof UserException) {
			UserException userException = (UserException)e;
			result.setCode(userException.getCode());
			result.setMsg(userException.getMsg());
		} else {
			result.setCode(500);
			result.setMsg("未知错误");
		}
		return result;
	}

}
